﻿using Sustainalytics.Claims;
using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;

namespace Sustainalytics.GCCS.Service.Controllers
{
    [EnableCors(origins: "*", headers: "*", methods: "*")]
    //[AutoInvalidateCacheOutput]
    [RoutePrefix("api/v1/gcprincipleeventindicatormanagement")]
    public class GCPrincipleEventIndicatorManagementController : ApiController
    {
        IGCPrincipleEventIndicatorManagementManager _manager;
        IClaimsChecker _claimsChecker;      

        public GCPrincipleEventIndicatorManagementController(IGCPrincipleEventIndicatorManagementManager manager, IClaimsChecker claimsChecker)
        {
            _manager = manager;
            _claimsChecker = claimsChecker;
        }


       // [CacheOutput(ServerTimeSpan = 100, ClientTimeSpan = 0, NoCache = true, MustRevalidate = true, Private = true)]
        [Route("")]
        public HttpResponseMessage Get(Guid principleSummaryId)
        {
            if (!_claimsChecker.ValidateNonCompliantOrWatchlist(this))
            {
                return this.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }

            // get principle event indicators management
            List<GCPrincipleEventIndicatorManagement> lst = _manager.GetList(principleSummaryId);

            // project to DTOs
            List<GCPrincipleEventIndicatorManagementDto> dtos = lst.Select(el => new GCPrincipleEventIndicatorManagementDto().LoadFrom(el)).ToList();

            return this.Request.CreateResponse(HttpStatusCode.OK, dtos);
        }
    }
}
